﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Forms;
using University.Workshop.Presenters.BackUp;
using Microsoft.Win32;
using Application = System.Windows.Application;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace University.Workshop.Presentation.BackUp
{
    /// <summary>
    /// Interaction logic for BackUp.xaml
    /// </summary>
    public partial class BackUp : Page, IBackUpView
    {
        private PresenterBackUp pBackUp;
        private bool fileOpened = false;

        public BackUp()
        {
            InitializeComponent();
            pBackUp=new PresenterBackUp(this);
            System.Windows.Application.Current.MainWindow.Title="UIBackUp";
        }

        private void MakeBackUp_Click(object sender, RoutedEventArgs e)
        {
            pBackUp.CreateBackUp();
        }

        public string BackUpName
        {
            get { return this.NameBackUpTxBx.Text; }
            set { NameBackUpTxBx.Text = value; }
        }

        public string BackUpUbication
        {
            get { return UbicationBackUpTxBx.Text; }
            set { UbicationBackUpTxBx.Text = value; }
        }
        
        public bool MessageConfirmation(string p)
        {
            return System.Windows.MessageBox.Show(App.Current.MainWindow,
                p,
                "Atencion!!!",
                MessageBoxButton.YesNo,
                MessageBoxImage.Information,
                MessageBoxResult.Yes,
                System.Windows.MessageBoxOptions.RightAlign) == MessageBoxResult.Yes;
        }

        private void MakeRestoreBtn_Click(object sender, RoutedEventArgs e)
        {
            pBackUp.MakeRestore();
        }


        public string RestoreUbication
        {
            get { return RestoreUbicationTxBx.Text; }
            set { RestoreUbicationTxBx.Text = value; }
        }

        private void RestoreUbicationTxBx_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            op.Title = "Buscar Croquis";
            op.Filter = "BackUp Documents (*.bak)|*.bak";
            if (op.ShowDialog() == true)
            {
                RestoreUbicationTxBx.Text = op.InitialDirectory + op.FileName;
            }
            
        
        }

        private void UbicationBackUpTxBx_PreviewGotKeyboardFocus(object sender, MouseButtonEventArgs e)
        {

            using (FolderBrowserDialog dlg = new FolderBrowserDialog())
            {
                dlg.Description = "Elejir la ubicacion del backup";
                dlg.SelectedPath = UbicationBackUpTxBx.Text;
                dlg.ShowNewFolderButton = true;
                DialogResult result = dlg.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                    UbicationBackUpTxBx.Text = dlg.SelectedPath;
            }
        }


        public void SystemMessage(string p)
        {
            System.Windows.MessageBox.Show(Application.Current.MainWindow,
                p,
                "Atencion!!!",
                MessageBoxButton.OK,
                MessageBoxImage.Warning,
                MessageBoxResult.OK,
                System.Windows.MessageBoxOptions.RightAlign);
        }

        public void ErrorMessage(string p)
        {
            System.Windows.MessageBox.Show(Application.Current.MainWindow,
                   p,
                   "Error!!!",
                   MessageBoxButton.OK,
                   MessageBoxImage.Error,
                   MessageBoxResult.OK,
                   System.Windows.MessageBoxOptions.RightAlign);
        }
    }
}
